﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Drawing;
using System.Text;
using System.Threading.Tasks;
using Homework.Properties;

namespace Homework
{
    class PlaneCold
    {
        //定义敌机速度
        private int SpeedY;
        //敌人飞机的生命值
        public int PlaneColdlifenow = 5;
        //获得游戏对象矩形
        public Rectangle rectangle { get; set; }
        //说明切换图片的布尔值
        private bool picture = true;
        //说明并初始化切换图片的时间
        private DateTime picturechanged = System.DateTime.Now.AddHours(-1);
        //说明闪烁的布尔值
        public bool Coldchanged;

        //敌人飞机飞机
        public PlaneCold(Rectangle rec, int PlaneEnenmytlifenow)
        {
            //给矩形赋值
            this.rectangle = rec;
            //给敌机初速度赋值
            SpeedY = 4;
        }

        /// <summary>
        /// 绘图函数
        /// </summary>
        /// <param name="graphics"></param>
        public void Draw(Graphics graphics)
        {
            //画飞机(被击中后闪烁)
            if (System.DateTime.Now > picturechanged)
            {
                if (Coldchanged == true)
                {
                    if (picture)
                    {
                        graphics.DrawImage(Properties.Resources.PlaneRtwo, rectangle);
                        picture = false;
                    }
                    else
                    {
                        graphics.DrawImage(Properties.Resources.PlaneRtwo2, rectangle);
                        picture = true;
                    }
                    picturechanged = System.DateTime.Now.AddSeconds(0.2);
                    Coldchanged = false;
                }
                else
                {
                    graphics.DrawImage(Properties.Resources.PlaneRtwo, rectangle);
                }
            }
            //画初始血条
            SolidBrush lifeEBrush = new SolidBrush(Color.Khaki);
            //画攻击血条
            SolidBrush attackedBrush = new SolidBrush(Color.Gold);
            //画将死血条
            SolidBrush deadBrush = new SolidBrush(Color.DarkGoldenrod);
            graphics.FillRectangle(lifeEBrush, this.rectangle.X - 2 + this.rectangle.Width / 2, this.rectangle.Y - 10, 50, 6);
            if (PlaneColdlifenow > 2 && PlaneColdlifenow < 5)
            {
                graphics.FillRectangle(attackedBrush, this.rectangle.X - 2 + this.rectangle.Width / 2, this.rectangle.Y - 10, PlaneColdlifenow * 10, 6);
            }
            else if (PlaneColdlifenow < 3)
            {
                graphics.FillRectangle(deadBrush, this.rectangle.X - 2 + this.rectangle.Width / 2, this.rectangle.Y - 10, PlaneColdlifenow * 10, 6);
            }

        }

        public void Move()
        {
            //让敌人飞机移动
            this.rectangle = new Rectangle(this.rectangle.X, this.rectangle.Y + SpeedY, rectangle.Width, rectangle.Height);
            //移动到低端后，让敌机出界         
            if (this.rectangle.Y >= 631)
            {
                this.rectangle = new Rectangle(this.rectangle.X, 1000, rectangle.Width, rectangle.Height);
            }
        }
    }
}
